﻿using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        DBHelper db = new DBHelper();
        DataSet set = new DataSet();
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            db.OpenConnection();
            string sql = "select * from TemaInfo";
            SqlDataAdapter adapter = new SqlDataAdapter(sql, db.Connection);
            adapter.Fill(set, "TemaInfo");
            this.comboBox1.DataSource = set.Tables["TemaInfo"];
            this.comboBox1.ValueMember = "id";
            this.comboBox1.DisplayMember = "teamName";
            db.CloseConnection();


           

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i;
            if (this.comboBox1.Text=="崔")
            {
                i = 1;
            }
           else if (this.comboBox1.Text == "雁")
            {
                i = 2;
            }
            else if (this.comboBox1.Text == "杰")
            {
                i = 3;
            }
            else
            {
                i = 4;
            }

            int p;
            if (this.comboBox2.Text == "崔")
            {
                p = 1;
            }
            else if (this.comboBox2.Text == "雁")
            {
                p = 2;
            }
            else if (this.comboBox2.Text == "杰")
            {
                p = 3;
            }
            else
            {
                p = 4;
            }

            if (this.comboBox1.Text==this.comboBox2.Text)
            {
                MessageBox.Show("队伍不能相同！！！");
                return;
            }

            db.OpenConnection();
            string sql = "insert ScheduleInfo(count,hostTeamID,awayTeamId,competitonTime,competitionposition,score,entryperson)values('"+this.textBox5.Text+"','"+i+"','"+p+"','"+this.textBox1.Text+"','"+this.textBox2.Text+ "','" + this.textBox2.Text + "','" + this.textBox2.Text + "')";
            SqlCommand comm = new SqlCommand(sql,db.Connection);
            int r = comm.ExecuteNonQuery();
            if (r>0)
            {
                MessageBox.Show("成功");

            }
            db.CloseConnection();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

        private void comboBox1_MouseEnter(object sender, EventArgs e)
        {
            
            
        }

        private void comboBox2_MouseEnter(object sender, EventArgs e)
        {
            if (this.comboBox2.Text == "")
            {
                db.OpenConnection();
                string sql1 = "select * from TemaInfo";
                SqlCommand comm = new SqlCommand(sql1, db.Connection);
                SqlDataReader reader = comm.ExecuteReader();

                

                while (reader.Read())
                {
                    for (int i = 0; i < 1; i++)
                    {
                        this.comboBox2.Text = reader["teamName"].ToString();
                    }
                    this.comboBox2.Items.Add(reader["teamName"]);
                }
               
                reader.Close();
                db.CloseConnection();
            }
            else
            {

            }
        }

        private void comboBox1_MouseDown(object sender, MouseEventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = null;
            this.textBox2.Text = null;
            this.textBox3.Text = null;
            this.textBox4.Text = null;
            this.textBox5.Text = null;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
